<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/11 0011
  Time: 下午 6:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<form class="layui-form" action="">
    <input type="hidden" name="id" id="id">
    <input type="hidden" name="orgId" id="orgId" value="${orgId}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最低消费额</label>
        <div class="layui-input-block">
            <input type="text" name="mixMoney" id="mixMoney" required  lay-verify="required|number" placeholder="最低消费额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">优惠券价值金额</label>
        <div class="layui-input-block">
            <input type="text" name="money" id="money" required  lay-verify="required|number" placeholder="请输入优惠券价值金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">优惠券售价</label>
        <div class="layui-input-block">
            <input type="text" name="price" id="price" required  lay-verify="required|number" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">优惠券备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" id="remark" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">优惠券发放方式</label>
        <div class="layui-input-block">
            <select name="giveType" id="giveType" lay-verify="">
                <option value="0">购买</option>
                <option value="1">填写信息</option>
                <option value="2">发朋友圈</option>
                <option value="3">发给朋友</option>
                <option value="4">下级点开链接</option>
                <option value="5">下级填写信息</option>
                <option value="6">下级购买</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-block">
            <input  name="startTime" id="startTime" lay-verify="datetime|required"
                    class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input  name="endTime" id="endTime" lay-verify="datetime|required"
                   class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">优惠券状态</label>
        <div class="layui-input-block">
            <input type="radio" name="state" value="0" title="上线使用">
            <input type="radio" name="state" value="1" title="暂时下线" >
        </div>
    </div>




    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form;
        var laydate=layui.laydate;
        laydate.render({
            elem: '#startTime',
            format:'yyyy-MM-dd HH:mm:ss'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endTime',
            format:'yyyy-MM-dd HH:mm:ss'
            ,type: 'datetime'
        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            console.log(JSON.stringify(data.field));
            $.ajax({
                url:'/marketing/saveVoucher',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    name:data.field.name,
                    mixMoney:data.field.mixMoney,
                    money:data.field.money,
                    price:data.field.price,
                    startTime:data.field.startTime,
                    endTime:data.field.endTime,
                    id:data.field.id,
                    remark:data.field.remark,
                    giveType:data.field.giveType,
                    orgId:'${orgId}',
                    activityId:'${activityId}',
                    state:data.field.state
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    console.log(data);
                    if (data.code=='000000'){
                        layer.msg(data.msg,{time:1000,icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else {
                        layer.msg(data.msg,{time:1000,icon: 5});
                    }
                    //console.log(data)
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            })


            return false;
        });
    });
</script>








<script>
    $(function () {
        var voucherInfo=JSON.parse($.cookie("couponsDate"));
        if (voucherInfo!=null){
            console.log(voucherInfo);
            $("#name").val(voucherInfo.name);
            $("#mixMoney").val(voucherInfo.mixMoney);
            $("#money").val(voucherInfo.money);
            $("#price").val(voucherInfo.price);
            $("#remark").val(voucherInfo.remark);
            $("#startTime").val(voucherInfo.startTime);
            $("#endTime").val(voucherInfo.endTime);
            $("#id").val(voucherInfo.id);
            $("#giveType").val(voucherInfo.giveType);
            $("input[name=state][value=" + voucherInfo.state + "]").attr("checked", true);
        }
    });

</script>

</body>
</html>
